package com.rzjm.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rzjm.api.dao.DeviceDao;
import com.rzjm.api.dao.DeviceWeldingDao;
import com.rzjm.api.dao.ShopDao;
import com.rzjm.api.entity.Device;
import com.rzjm.api.entity.DeviceWelding;
import com.rzjm.api.entity.Shop;
import com.rzjm.api.entity.User;
import com.rzjm.api.service.DeviceWeldingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DeviceWeldingServiceImpl extends BaseServiceImpl<DeviceWeldingDao, DeviceWelding> implements DeviceWeldingService {

    @Resource
    private DeviceWeldingDao deviceWeldingDao;
    @Resource
    private ShopDao shopDao;

    @Override
    public List<DeviceWelding> getDeviceList(User user,Integer device_type,Integer pageSize,Integer pageIndex) {
        QueryWrapper<DeviceWelding> qw = new QueryWrapper<>();
        qw.eq("shop_id",user.getShopId());
//        qw.eq("leader_wx_user_id",user.getId());
        qw.and(
                wrapper -> wrapper.eq("device_type", device_type).or().eq("device_type",2)
        );
        List<DeviceWelding> list = deviceWeldingDao.getPageEntityList(qw, pageIndex, pageSize);
        if(list != null && list.size() > 0){
            for (DeviceWelding device : list){
                Shop shop = shopDao.selectById(device.getShopId());
                if(shop!=null){
                    device.setShopName(shop.getShopName());
                }
            }
        }
        return list;
    }
}
